package cc.sunni.sleeve.vo;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 分页数据进行类型转换
 */
public class PagingDozer<T, K> extends Paging {

    public PagingDozer(Page<T> pageT, Class<K> classK) {
        this.initPageParameters(pageT);
        List<T> tList = pageT.getContent();
        Mapper mapper = DozerBeanMapperBuilder.buildDefault();
        List<K> voList = tList.stream().map(t -> mapper.map(t, classK)).collect(Collectors.toList());
        this.setItems(voList);
    }
}
